package com.game.battleship.data;

import java.io.Serializable;

/**
 * This class stores the mLength of a game ship and indexes of the fields on which it resides
 * on the game board.It also sustain state of destruction for every ship
 * @author vasil.konstantinov
 *
 */
public class Ship implements Serializable {
	
	//TODO : implement logic that stores state of the Ship's attacked field in order
	//a ship to be able to return its "Life" status.
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@SuppressWarnings("unused") //needed if there is superweapons mode,or "move ship mode"
	private Short[] board;
	
	private short mLength;
	private short mHitCounts = 0;
	
	/*stores indexes of mBoardCells*/
	private int[] mBoardCells;
	
	/**
	 * @return - the mLength of the ship
	 */
	public short getLength(){
		return this.mLength;
	}
	
	/**
	 * @return the mBoardCells
	 */
	public int[] getBoardCells() {
		return mBoardCells;
	}
	
	public int getCell(short index) {
		return mBoardCells[index];
	}
	
	/**
	 * Constructor
	 * @param mLength
	 * @param _fields
	 */
	public Ship(short length, int[] _fields) {
		this.mLength = length;
		this.mBoardCells = _fields;
	}
	/**
	 * 
	 * @param attackedCell - the attacked field 
	 * @return weather ship was hit or missed
	 */
	public boolean isAttackedShip(int attackedCell){
		for(int i = 0 ; i < mBoardCells.length ; i++){
			if(mBoardCells[i] == attackedCell){
				return true;
			}
		}
		return false;
	}
	
	public void increaseHitCounts() {
		mHitCounts++;
	}
	
	/**
	 * @return whether or not all ship fields are attacked
	 */
	public boolean isShipDestroyed(){
		return this.mLength == mHitCounts;
	}
	
	/**
	 * @return the number of attacked fields of the ship
	 */
	public short getShipHitStatus(){
		return mHitCounts;
	}
}
